package values.inventory
{
import utils.VectorUtil;

import values.item.IItemValue;

/**
 * UniqueItemInventoryValue
 * @author jliang
 *
 */
public class UniqueItemInventoryValue extends InventoryValue
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function UniqueItemInventoryValue()
	{
		super();
	}
	//==========================================================================
	//  Overridden methods: InventoryValue
	//==========================================================================
	override public function addItem(value:IItemValue):*
	{
		if (isFull)
		{
			dispatchFullEvent();
			
			return null;
		}
		
		items.push(value);
		
		if (isFull)
		{
			dispatchFullEvent();
		}
		
		return value;
	}
	
	override public function removeItem(value:IItemValue):*
	{
		VectorUtil.removeObject(value, items);
		return value;
	}
	
	override public function hasEnoughSpace(value:IItemValue):Boolean
	{
		if (isFull) return false;
		
		if (items.length + 1 > currentSpace) return false;
		
		return true;
	}
    
    override public function getItemNumByKey(itemKey:String):Number
    {
        var num:Number = 0;
        for each (var item:IItemValue in items)
        {
            if (item.key == itemKey) num ++;
        }
        return num;
    }
	
	override protected function findItem(key:String):*
	{
		var list:Vector.<IItemValue> = new Vector.<IItemValue>();
		for each (var vo:IItemValue in items)
		{
			if (vo.key == key) list.push(vo);
		}
		return list;
	}
}
}



